﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class NewsType_add : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
            ddlPid.DataSource = dal.NewsType.Where(x=>string.IsNullOrEmpty(x.pid));
            ddlPid.DataValueField = "id";
            ddlPid.DataTextField = "name";
            ddlPid.DataBind();
            ddlPid.Items.Insert(0, new ListItem("无", ""));
            
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {

        CMSModel.NewsType type = new CMSModel.NewsType();
        type.ctime = DateTime.Now;
        type.enable =int.Parse( Request["type"]);
        type.id = txtId.Text;
        type.name = txtName.Text;
        type.memo = txtMemo.Text;
        type.pid = ddlPid.SelectedValue;
        if (string.IsNullOrEmpty(type.pid))
            type.pid = null;
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        try
        {
            dal.AddToNewsType(type);
            dal.SaveChanges();
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('添加成功'),document.location='Default.aspx'", true);
        }
        catch(Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.error).Write(GetType(), "addNewsType", LogYuMin.LogStates.ERROR, ex);
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('添加失败')", true);
        }
    }
}